/*
 * AppGUI.java
 *
 * Created on 23 de Maio de 2008, 19:07
 */

package protocolo.gui;

import event.GetEvent;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

/**
 *
 * @author  joao
 */
public class AppGUI extends javax.swing.JFrame {

    /** Creates new form AppGUI */
    public AppGUI() {
        initComponents();
        myModification();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        painelFormulario = new javax.swing.JPanel();
        labelQuantidade = new javax.swing.JLabel();
        fieldQuantidade = new javax.swing.JFormattedTextField();
        labelValorInicial = new javax.swing.JLabel();
        fieldValorInicial = new javax.swing.JFormattedTextField();
        labelAno = new javax.swing.JLabel();
        fieldAno = new javax.swing.JFormattedTextField();
        jLabel1 = new javax.swing.JLabel();
        fieldControle = new javax.swing.JFormattedTextField();
        jPanel1 = new javax.swing.JPanel();
        botaoVisualizar = new javax.swing.JButton();
        botaoImprimir = new javax.swing.JButton();
        botaoSair = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        menuArquivo = new javax.swing.JMenu();
        arquivo_imprimir = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        arquivo_sair = new javax.swing.JMenuItem();
        menuConfiguracao = new javax.swing.JMenu();
        configuracao_imrpessao = new javax.swing.JMenuItem();
        menuSobre = new javax.swing.JMenu();
        sobre_autor = new javax.swing.JMenuItem();

        FormListener formListener = new FormListener();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Protocolos CEFET");
        setResizable(false);

        painelFormulario.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        painelFormulario.setName("painelFormulario"); // NOI18N
        painelFormulario.setLayout(new java.awt.GridBagLayout());

        labelQuantidade.setText("Quantidade:");
        labelQuantidade.setName("labelQuantidade"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.gridheight = 3;
        gridBagConstraints.ipady = 13;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(9, 19, 0, 0);
        painelFormulario.add(labelQuantidade, gridBagConstraints);

        try {
            fieldQuantidade.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        fieldQuantidade.setText("020");
        fieldQuantidade.setName("fieldQuantidade"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.ipadx = 70;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(9, 12, 0, 0);
        painelFormulario.add(fieldQuantidade, gridBagConstraints);

        labelValorInicial.setText("Valor inicial:");
        labelValorInicial.setName("labelValorInicial"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipady = 13;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(9, 19, 0, 0);
        painelFormulario.add(labelValorInicial, gridBagConstraints);

        try {
            fieldValorInicial.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        fieldValorInicial.setText("001");
        fieldValorInicial.setName("fieldValorInicial"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.ipadx = 32;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(9, 12, 0, 0);
        painelFormulario.add(fieldValorInicial, gridBagConstraints);

        labelAno.setText("Ano:");
        labelAno.setName("labelAno"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipady = 13;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(9, 10, 0, 0);
        painelFormulario.add(labelAno, gridBagConstraints);

        try {
            fieldAno.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        fieldAno.setText("2008");
        fieldAno.setName("fieldAno"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 7;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.ipadx = 42;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(9, 11, 0, 0);
        painelFormulario.add(fieldAno, gridBagConstraints);

        jLabel1.setText("Controle:");
        jLabel1.setName("jLabel1"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 7;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.gridheight = 4;
        gridBagConstraints.ipady = 13;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        painelFormulario.add(jLabel1, gridBagConstraints);

        try {
            fieldControle.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("#####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        fieldControle.setName("fieldControle"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 9;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 60;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 12, 0, 0);
        painelFormulario.add(fieldControle, gridBagConstraints);

        getContentPane().add(painelFormulario, java.awt.BorderLayout.CENTER);

        jPanel1.setBorder(null);
        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 10, 5));

        botaoVisualizar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/gtk-print-preview.png"))); // NOI18N
        botaoVisualizar.setText("Visualizar");
        botaoVisualizar.setEnabled(false);
        botaoVisualizar.setName("botaoVisualizar"); // NOI18N
        botaoVisualizar.addActionListener(formListener);
        jPanel1.add(botaoVisualizar);

        botaoImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/gtk-print.png"))); // NOI18N
        botaoImprimir.setMnemonic('p');
        botaoImprimir.setText("Imprimir");
        botaoImprimir.setName("botaoImprimir"); // NOI18N
        botaoImprimir.addActionListener(formListener);
        jPanel1.add(botaoImprimir);

        botaoSair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/gtk-quit.png"))); // NOI18N
        botaoSair.setText("Sair");
        botaoSair.setName("botaoSair"); // NOI18N
        botaoSair.addActionListener(formListener);
        jPanel1.add(botaoSair);

        getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END);

        jMenuBar1.setName("jMenuBar1"); // NOI18N

        menuArquivo.setText("Arquivo");
        menuArquivo.setName("menuArquivo"); // NOI18N

        arquivo_imprimir.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
        arquivo_imprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/gtk-print.png"))); // NOI18N
        arquivo_imprimir.setText("Imprimir");
        arquivo_imprimir.setName("arquivo_imprimir"); // NOI18N
        menuArquivo.add(arquivo_imprimir);

        jSeparator1.setName("jSeparator1"); // NOI18N
        menuArquivo.add(jSeparator1);

        arquivo_sair.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        arquivo_sair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/gtk-quit.png"))); // NOI18N
        arquivo_sair.setText("Sair");
        arquivo_sair.setName("arquivo_sair"); // NOI18N
        arquivo_sair.addActionListener(formListener);
        menuArquivo.add(arquivo_sair);

        jMenuBar1.add(menuArquivo);

        menuConfiguracao.setText("Configurações");
        menuConfiguracao.setName("menuConfiguracao"); // NOI18N

        configuracao_imrpessao.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/gtk-preferences.png"))); // NOI18N
        configuracao_imrpessao.setText("Configurar impressão");
        configuracao_imrpessao.setEnabled(false);
        configuracao_imrpessao.setName("configuracao_imrpessao"); // NOI18N
        configuracao_imrpessao.addActionListener(formListener);
        menuConfiguracao.add(configuracao_imrpessao);

        jMenuBar1.add(menuConfiguracao);

        menuSobre.setText("Sobre");
        menuSobre.setName("menuSobre"); // NOI18N

        sobre_autor.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/gtk-help.png"))); // NOI18N
        sobre_autor.setText("Autor");
        sobre_autor.setName("sobre_autor"); // NOI18N
        sobre_autor.addActionListener(formListener);
        menuSobre.add(sobre_autor);

        jMenuBar1.add(menuSobre);

        setJMenuBar(jMenuBar1);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-383)/2, (screenSize.height-200)/2, 383, 200);
    }

    // Code for dispatching events from components to event handlers.

    private class FormListener implements java.awt.event.ActionListener {
        FormListener() {}
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (evt.getSource() == botaoVisualizar) {
                AppGUI.this.botaoVisualizarActionPerformed(evt);
            }
            else if (evt.getSource() == botaoImprimir) {
                AppGUI.this.botaoImprimirActionPerformed(evt);
            }
            else if (evt.getSource() == botaoSair) {
                AppGUI.this.botaoSairActionPerformed(evt);
            }
            else if (evt.getSource() == arquivo_sair) {
                AppGUI.this.arquivo_sairActionPerformed(evt);
            }
            else if (evt.getSource() == configuracao_imrpessao) {
                AppGUI.this.configuracao_imrpessaoActionPerformed(evt);
            }
            else if (evt.getSource() == sobre_autor) {
                AppGUI.this.sobre_autorActionPerformed(evt);
            }
        }
    }// </editor-fold>//GEN-END:initComponents

private void arquivo_sairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_arquivo_sairActionPerformed
        System.exit(0);
}//GEN-LAST:event_arquivo_sairActionPerformed

private void botaoImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoImprimirActionPerformed
        try {
            new GetEvent().imprimirEvent(fieldAno.getText(), fieldQuantidade.getText(), 
                    fieldValorInicial.getText(), fieldControle.getText());
        } catch (IOException ex) {//GEN-LAST:event_botaoImprimirActionPerformed
            Logger.getLogger(AppGUI.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        botaoVisualizar.setEnabled(true);
}

private void botaoSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoSairActionPerformed
    System.exit(0);
}//GEN-LAST:event_botaoSairActionPerformed

private void botaoVisualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoVisualizarActionPerformed
    new GetEvent().visualizarEvent();
}//GEN-LAST:event_botaoVisualizarActionPerformed

private void configuracao_imrpessaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configuracao_imrpessaoActionPerformed
    new GetEvent().configurationEvent();
}//GEN-LAST:event_configuracao_imrpessaoActionPerformed

private void sobre_autorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sobre_autorActionPerformed
    new GetEvent().autor();
}//GEN-LAST:event_sobre_autorActionPerformed

    private void myModification() {
        String l = UIManager.getSystemLookAndFeelClassName();
        try {
            UIManager.setLookAndFeel(l);
            SwingUtilities.updateComponentTreeUI(this);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public String getfieldAno() {
        return fieldAno.getText();
    }
    
    public String getFieldQuantidade () {
        return fieldQuantidade.getText();
    }
    
    public String getFieldAno () {
        return fieldAno.getText();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem arquivo_imprimir;
    private javax.swing.JMenuItem arquivo_sair;
    private javax.swing.JButton botaoImprimir;
    private javax.swing.JButton botaoSair;
    private javax.swing.JButton botaoVisualizar;
    private javax.swing.JMenuItem configuracao_imrpessao;
    private javax.swing.JFormattedTextField fieldAno;
    private javax.swing.JFormattedTextField fieldControle;
    private javax.swing.JFormattedTextField fieldQuantidade;
    private javax.swing.JFormattedTextField fieldValorInicial;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel labelAno;
    private javax.swing.JLabel labelQuantidade;
    private javax.swing.JLabel labelValorInicial;
    private javax.swing.JMenu menuArquivo;
    private javax.swing.JMenu menuConfiguracao;
    private javax.swing.JMenu menuSobre;
    private javax.swing.JPanel painelFormulario;
    private javax.swing.JMenuItem sobre_autor;
    // End of variables declaration//GEN-END:variables

}
